import java.util.ArrayList;

public class StudentListRepo implements StudentRepo {
    private final ArrayList<Student> students = new ArrayList<>();

    @Override
    public void deleteStudent(String stuNum1) {

        // 在学生列表中查找学生
        for (Student student : students) {
            // 根据学号来查询
            String stuNum = student.getStuNum();
            if (stuNum.equals(stuNum1)) {
                //查询到了要删除的学生
                students.remove(student);
                return;
            }
        }
    }

    @Override
    public void updateStudent(Student student) {
        Student student1 = this.findStudent(student.getStuNum());

        student1.setClassName(student.getClassName());
        student1.setName(student.getName());
        student1.setSex(student.getSex());
        student1.setAge(student.getAge());
    }


    public Student findStudent(String s) {

        // 在学生列表中查找学生
        for (Student student : students) {
            // 根据学号 或姓名 来查询
            String stuNum = student.getStuNum();
            String name = student.getName();
            if (stuNum.equals(s) || name.equals(s)) {
                return student;
            }
        }
        return null;
    }

    public void newStudent(Student student) {
        // 放入学生列表
        students.add(student);
    }
}
